package com.shy.springframework.aop.framework.adapter;

import com.shy.springframework.aop.MethodAfterAdvice;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

import java.lang.reflect.Method;

/**
 * @author yzpang
 * @desc:
 * @date: 2023/2/13 9:59
 */
public class MethodAfterAdviceInterceptor implements MethodInterceptor {
    private MethodAfterAdvice advice;

    public MethodAfterAdviceInterceptor() {
    }

    public MethodAfterAdviceInterceptor(MethodAfterAdvice advice) {
        this.advice = advice;
    }

    @Override
    public Object invoke(MethodInvocation invocation) throws Throwable {
        try{
            return invocation.proceed();
        }finally {
           advice.after(invocation.getMethod(), invocation.getArguments(), invocation.getThis());
        }
    }
}
